home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
dl_exsrc.zoo
/
splitpth.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-03
|
2KB
|
80 lines
#include <string.h>
#include <ctype.h>
#include "extras.h"
char *_splitpath(src, drive, path, file, ext)
const char *src;
char *drive, *path, *file, *ext;
{
register const char *s = src;
register char *t;
int rooted; /* detect "a:filename.ext" */
/* Get drive section. We also recognize and translate the MiNT
device "/dev/a" as "a:". */
if (isalpha(*s) && s[1] == ':') {
rooted = 1;
if (drive) {
t = drive;
*t++ = *s;
*t++ = ':';
*t = '\0';
}
s += 2;
} else if (strncmp(s, "/dev/", 5) == 0 && isalpha(s[5])) {
rooted = 1;
if (drive) {
t = drive;
*t++ = s[5];
*t++ = ':';
*t = '\0';
}
s += 6;
} else {
rooted = 0;
if (drive)
*drive = '\0';
}
/* Get path section. We translate all /'s to \'s. */
t = strrpbrk(s, "/\\");
if (!t || t == s) {
if (path && (*s == '/' || *s == '\\' || rooted)) {
path[0] = '\\';
path[1] = '\0';
}
if (t)
s++;
} else {
if (path) {
strncpy(path, s, (int)(t - s));
path[(int)(t - s)] = '\0';
}
s = t + 1;
#if 1 /* maybe don't do this */
if (path) {
for (t = path; *t; t++)
if (*t == '/')
*t = '\\';
}
#endif
}
/* Get filename and extension. Note that only the last '.' is
recognized; the filename "fred.tar.Z" would split into "fred.tar"
and "Z". */
t = strrchr(s, '.');
if (ext) {
if (t)
strcpy(ext, t + 1);
else
ext[0] = '\0';
}
if (file) {
strncpy(file, s, (int)(t - s));
file[(int)(t - s)] = '\0';
}
return src;
}